Add shortname support for Garmin Mapsource.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 15 Jan 2003 17:02:31 +0000 (17:02 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 15 Jan 2003 17:02:31 +0000 (17:02 +0000)
gpsbabel/mapsource.c

index 5d58fdbbc9f26c92552458854e415e579fa30edd..1458c387a432a750ade87d2fd3c75df679b3efe1 100644 (file)
@@ -213,7 +213,9 @@ mps_read(void)
 static void
 mps_waypt_pr(const waypoint *wpt)
 {
-       int reclen = 87 + strlen(wpt->shortname) + strlen(wpt->description);
+       char *src;
+       char *ident;
+       int reclen;
        char zbuf[100];
        char ffbuf[100];
        char display = 1;
@@ -221,6 +223,14 @@ mps_waypt_pr(const waypoint *wpt)
        int lat = wpt->position.latitude.degrees  / 180.0 * 2147483648.0;
        int lon = wpt->position.longitude.degrees  / 180.0 * 2147483648.0;
 
+       if(wpt->description) src = wpt->description;
+       if(wpt->notes) src = wpt->notes;
+       ident = global_opts.synthesize_shortnames ?
+                               mkshort(src) :
+                               wpt->shortname;
+
+       reclen = 87 + strlen(ident) + strlen(wpt->description);
+
        memset(zbuf, 0, sizeof(zbuf));
        memset(ffbuf, 0xff, sizeof(ffbuf));
 
@@ -229,7 +239,7 @@ mps_waypt_pr(const waypoint *wpt)
        le_write32(&reclen, reclen);
        fwrite(&reclen, 4, 1, mps_file_out);
        fwrite("W", 1, 1, mps_file_out);
-       fputs(wpt->shortname, mps_file_out);
+       fputs(ident, mps_file_out);
        fwrite(zbuf, 1, 1, mps_file_out);
        fwrite(zbuf, 9, 1, mps_file_out);
        fwrite(ffbuf, 12, 1, mps_file_out);
@@ -253,6 +263,11 @@ mps_waypt_pr(const waypoint *wpt)
 void
 mps_write(void)
 {
+       int short_length = 10;
+
+       setshort_length(short_length);
+       setshort_whitespace_ok(0);
+
        fwrite(mps_hdr, sizeof(mps_hdr), 1, mps_file_out);
        waypt_disp_all(mps_waypt_pr);
        fwrite(mps_ftr, sizeof(mps_ftr), 1, mps_file_out);